#ifndef _ROSTERGROUP_H_
#define _ROSTERGROUP_H_

#include <string>
#include <list>

class XMPPConnection;
class RosterEntry;

/**
 * A group of roster entries.
 *
 * @see Roster#getGroup(String)
 * @author Matt Tucker
 */
class RosterGroup {
public:
    /**
     * Creates a new roster group instance.
     *
     * @param name the name of the group.
     * @param connection the connection the group belongs to.
     */
    RosterGroup(std::string & name, XMPPConnection * connection) ;
	
    /**
     * Returns the name of the group.
     *
     * @return the name of the group.
     */
	std::string getName() {
        return name;
    }

    /**
     * Sets the name of the group. Changing the group's name is like moving all the group entries
     * of the group to a new group specified by the new name. Since this group won't have entries 
     * it will be removed from the roster. This means that all the references to this object will 
     * be invalid and will need to be updated to the new group specified by the new name.
     *
     * @param name the name of the group.
     */
    void setName(std::string & name) ;
	
    /**
     * Returns the number of entries in the group.
     *
     * @return the number of entries in the group.
     */
    int getEntryCount() {
        //synchronized (entries) { there should be a mutex in entries
        //}
        return entries.size();
    }

	/**
     * Returns an unmodifiable collection of all entries in the group.
     *
     * @return all entries in the group.
     */
	std::list<RosterEntry*> & getEntries() {
        //synchronized (entries) {
        //}
        return entries;
    }
	
    /**
     * Returns the roster entry associated with the given XMPP address or
     * <tt>null</tt> if the user is not an entry in the group.
     *
     * @param user the XMPP address of the user (eg "jsmith@example.com").
     * @return the roster entry or <tt>null</tt> if it does not exist in the group.
     */
    RosterEntry * getEntry(std::string & user) ;
	
    /**
     * Returns true if the specified entry is part of this group.
     *
     * @param entry a roster entry.
     * @return true if the entry is part of this group.
     */
    bool contains(RosterEntry * entry);

    /**
     * Returns true if the specified XMPP address is an entry in this group.
     *
     * @param user the XMPP address of the user.
     * @return true if the XMPP address is an entry in this group.
     */
    bool contains(std::string & user) {
        return getEntry(user) != NULL;
    }


    /**
     * Adds a roster entry to this group. If the entry was unfiled then it will be removed from 
     * the unfiled list and will be added to this group.
     *
     * @param entry a roster entry.
     * @throws XMPPException if an error occured while trying to add the entry to the group.
     */
    void addEntry(RosterEntry * entry);
	
    /**
     * Removes a roster entry from this group. If the entry does not belong to any other group 
     * then it will be considered as unfiled, therefore it will be added to the list of unfiled 
     * entries.
     *
     * @param entry a roster entry.
     * @throws XMPPException if an error occured while trying to remove the entry from the group. 
     */
    void removeEntry(RosterEntry * entry) ;
	
    void addEntryLocal(RosterEntry * entry);

    void removeEntryLocal(RosterEntry * entry) ;

private:
	std::string name;
    XMPPConnection * connection;
	std::list<RosterEntry*> entries;
};
#endif // -- _ROSTERGROUP_H_
